package com.mashibing.common.factory;


import com.mashibing.common.exception.ModuleException;

/**
 * 异常代码工厂类
 */
public final class ExceptionCodeFactory {

    // 默认的异常响应码
    private static final Integer defaultCode = Integer.valueOf("" + 99 + 9999 + 9);

    private ExceptionCodeFactory() {
    }

    public static Integer getExceptionCode(Class<?> clazz, int code) {

        if (clazz == null) {
            return defaultCode;
        } else {
            ModuleException moduleException = clazz.getAnnotation(ModuleException.class);
            if (moduleException == null) {
                return defaultCode;
            }
            return Integer.valueOf("" + moduleException.module() + moduleException.category() + code);
        }

    }

}
